// 折半查找

#include <stdio.h>
int main() {
	int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
	int key = 5; //要找的数字
	int left = 0; 
	int mid = 0; //记录中间元素的下标
	int find = 0;

	int right = (sizeof(arr) / sizeof(arr[0])) - 1;

	while (left <= right) {
		int mid = left + (right - left) / 2;
		if (key > arr[mid]) {
			left = mid + 1;
		}
		else if (key < arr[mid]) {
			right = mid - 1;
		}
		else {
			find = 1;
			break;
		}
	}

	if (1 != find)
		printf("未找到key\n");
	else
		printf("找到中间值：%d", key);
	return 0;
}
